-
Notifications
You must be signed in to change notification settings - Fork 14k
Add Drop::pin_drop for pinned drops
#144537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
362f769 to
1497185
Compare
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
1497185 to
9b7201c
Compare
Drop::pin_drop for !Unpin typesDrop::pin_drop for pinned drops
This comment has been minimized.
This comment has been minimized.
d6ddfcf to
7b4bb5c
Compare
This comment has been minimized.
This comment has been minimized.
7b4bb5c to
36ca628
Compare
This comment has been minimized.
This comment has been minimized.
36ca628 to
252d6fc
Compare
This comment has been minimized.
This comment has been minimized.
|
The CI failed because |
252d6fc to
02b0b0d
Compare
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
02b0b0d to
7660d88
Compare
This comment has been minimized.
This comment has been minimized.
7660d88 to
33e3124
Compare
This comment has been minimized.
This comment has been minimized.
6303109 to
9618d10
Compare
9618d10 to
c3e34d5
Compare
|
rustbot has assigned @petrochenkov. Use |
|
|
☔ The latest upstream changes (presumably #148397) made this pull request unmergeable. Please resolve the merge conflicts. |
| hir_analysis_coercion_between_struct_single_note = expected a single field to be coerced, none found | ||
| hir_analysis_conflict_impl_drop_and_pin_drop = conflict implementation of `Drop::drop` and `Drop::pin_drop` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| hir_analysis_conflict_impl_drop_and_pin_drop = conflict implementation of `Drop::drop` and `Drop::pin_drop` | |
| hir_analysis_conflict_impl_drop_and_pin_drop = conflicting implementations of `Drop::drop` and `Drop::pin_drop` |
| if tcx.is_lang_item(trait_id, LangItem::Drop) | ||
| // Allow calling `Drop::pin_drop` in `Drop::drop` | ||
| && let Some(parent) = tcx.opt_parent(body_id) | ||
| && !tcx.is_lang_item(parent, LangItem::Drop) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| && !tcx.is_lang_item(parent, LangItem::Drop) | |
| && !tcx.is_lang_item(tcx.parent(body_id), LangItem::Drop) |
Body id should have a parent, but if it somehow doesn't, we certainly shouldn't skip the code below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, calling the destructor explicitly should probably be unsafe?
| let mut pin_drop_span = None; | ||
| for &impl_item_id in item_impl.items { | ||
| let impl_item = tcx.hir_impl_item(impl_item_id); | ||
| if let hir::ImplItemKind::Fn(fn_sig, _) = impl_item.kind { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some HIR is accessed on a good path here, ideally queries should be used and HIR accesses should be avoided for better incremental compilation (or only performed when errors are reported).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean using queries like asspciated_items or I should add a new query like this?
rustc_queries! {
query drop_impl_fn_items(impl_id: DefId) -> DropImplFnItems { ... }
}
pub struct DropImplFnItems {
pub drop: Option<DefId>,
pub pin_drop: Option<DefId>,
}Or let the query return spans of drop and pin_drop directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using existing queries like associated_items should be enough.
| --> $DIR/missing-drop-method.rs:2:1 | ||
| | | ||
| LL | impl Drop for DropNoMethod {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `drop` in implementation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can report the old error if tcx.features().pin_ergonomics() is not enabled?
|
The |
|
Let's run benchmarks first. @bors try @rust-timer queue |
|
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
|
🔒 Merge conflict This pull request and the base branch diverged in a way that cannot How do I rebase?Assuming
You may also read Please avoid the "Resolve conflicts" button on GitHub. Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how |
|
Needs a rebase for perf run. |
|
Reminder, once the PR becomes ready for a review, use |
One test would fail without that change, see |
Then the change needs to be merged into the book's master first (right now I'm not sure where the new submodule is pointing to). |
This PR is part of the
pin_ergonomicsexperiment (the tracking issue is #130494). It allows implementingDropwith a pinnedselfreceiver, which is required for safe pin-projection.Implementations:
dropandpin_dropshould be implemented.droporpin_drop. They should only be called by the drop glue.pin_dropmust and must only be used with types that support pin-projection (i.e. types with#[pin_v2]).fn drop(&pin mut self)and desugars tofn pin_drop(&pin mut self). (Will be in the next PRs)